package com.wzu;

import java.sql.*;

public class First {
    public static void main(String[] args) {
        try {
            Class.forName("com.mysql.cj.jdbc.Driver");
            // 修改数据库连接的 URL，使用新的主机和端口
            Connection conn = DriverManager.getConnection("jdbc:mysql://gz-cynosdbmysql-grp-l5p5nhsn.sql.tencentcdb.com:26312/bookmanagement?serverTimezone=UTC", "root", "Mouse1121332661!");
            String sql = "select * from user";
            Statement statement = conn.createStatement();
            ResultSet rs = statement.executeQuery(sql);
            while (rs.next()) {
                int id = rs.getInt("id");
                String username = rs.getString("name");
                String password = rs.getString("password");
                System.out.println(id + "---" + username + "---" + password);
            }
            rs.close();
            statement.close();
            conn.close();
        } catch (ClassNotFoundException | SQLException e) {
            e.printStackTrace();
        }
    }
}